package org.example.Servlet.relation;

import cn.hutool.json.JSONUtil;
import org.example.utils.EmailUtil;

import javax.mail.MessagingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/relation")
public class RelationServlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String email = req.getParameter("email");
        String subject = req.getParameter("subject");
        String content = req.getParameter("content");
        try {
            EmailUtil.contantAdmin(name, subject, email, content);
            resp.getWriter().write(JSONUtil.toJsonStr("success"));
        } catch (MessagingException e) {
            System.out.println("relation admin error ==>" + e.getMessage());
        }
    }
}
